<%@ page language="java" pageEncoding="UTF-8"%>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery.form.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/JSON2.js"></script>
	<script type="text/javascript">
		window.APNS = {
				context:{
					getContextPath:function()
					{
						return "<%=request.getContextPath()%>";
					},
					getContextUrl:function( url)
					{
						return ["<%=request.getContextPath()%>",url].join("");
					}
				},
				util:{},form:{}
		};
		
		APNS.util.getFormValue = function(formId, attrName) {
			return $("#"+formId + " [name='"+attrName+"']").val();
		};
		
		function alertError( req, status, setting)
		{
			var responseText = req.responseText;
			if(responseText.length > 100)
			{
				responseText = responseText.substr( 0, 100) + "...";
			}
			
			var message = [
			"[APNS.util.doAjax] - 에러가 발생하였습니다. 첫페이지로 이동하시겠습니끼?",
			"  URL : " + setting.url,
			"  Response : " + responseText
			];
			if(confirm( message.join("\n")))
			{
				document.location.replace( APNS.context.getContextPath());
			};
		}
		
		APNS.util.doAjax = function(setting)
		{
			$.ajax({
				header:{"INVOKE_TYPE":"AJAX"},
				url: setting.url,
				async: setting.async||false,
				type: setting.type||"POST",
				dataType: setting.dataType||"text",
				data: setting.data,
				complete: function(req, status) {
					if( status == "error")
					{
						alertError( req, status, setting);
					}
					if( setting.complete) 
					{
						setting.complete( req, status);
					}
				},
				success: setting.success,
				error: setting.error
			});
		}
		
		/***
		 * ajax 실행 결과를 함수의 리턴값으로 활용한다.
		 */
		APNS.util.doAjaxResponse = function(setting)
		{
			var response = null;
			$.ajax({
				header:{"INVOKE_TYPE":"AJAX"},
				url: setting.url,
				/* 무조건 false 로 하여 리턴을 강제한다. */
				async: false,
				type: setting.type||"POST",
				dataType: setting.dataType||"text",
				data: setting.data,
				complete: function(req, status) {
					if(status == "error")
					{
						alertError( req, status, setting);
					}
					else if( status == "sucess")
					{
						if( setting.complete) {
							setting.complete( req, status);
						}
						response = req.responseText;
					}
				},
				success: setting.success,
				error: setting.error
			});
			
			return response;
		}
		
		APNS.util.doAjaxForm = function( formId, setting)
		{
			$("#"+formId).ajaxForm({
				header:{"INVOKE_TYPE":"AJAX"},
				url: setting.url,
				async: setting.async||false,
				type: setting.type||"POST",
				dataType: setting.dataType||"text",
				data: setting.data,
				complete: function(req, status) {
					if( status == "error")
					{
						alertError( req, status, setting);
					}
					if( setting.complete) 
					{
						setting.complete( req, status);
					}
				},
				success: setting.success,
				error: setting.error
			}).submit();
		}
		
		APNS.form.toStringArray = function(formObjArray, delimiter)
		{
			delimiter = delimiter||",";
			var formObjList = [];
			$(formObjArray).each(function(i){
				formObjList.push($(this).val());
			});
			return formObjList.join(delimiter);
		}
	</script>
	<style type="text/css">
		table th {background-color: #ECECEC;border: 1px solid #696969}
		table td {border-bottom: 1px solid #696969;}
	</style>